package com.atguigu.tingshu.album.config;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

// 使用Bean实现 MinioClient 的好处是保证了 MinioClient 单例模式，否者每次上传都会创建一个MinioClient很吃内存
@Configuration
public class MinIoClientConfig {

    @Autowired
    private MinioConstantProperties properties;

    @Bean
    public MinioClient minioClient(){
        return  MinioClient.builder()
                .endpoint(properties.getEndpointUrl())
                .credentials(properties.getAccessKey(), properties.getSecreKey())
                .build();
    }
}
